package com.dlmz.view;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.dlmz.model.Healthform;
import com.dlmz.util.BaseDao;
import com.dlmz.util.ResultsetToHealthform;

@SuppressWarnings("serial")
public class HealModel extends AbstractTableModel{

	@SuppressWarnings("rawtypes")
	private Vector columnNames;  
    @SuppressWarnings("rawtypes")
	private Vector rowDates;  
    
      
    //========增删改学生  
//    public boolean cudStu(String sql, String []paras)  
//    {  
//        return new SqlHelper().cudExecute(sql, paras);  
//    }  
      
    //========查询学生  
    @SuppressWarnings({ "unchecked", "rawtypes" })
	public void queryHeal(String sql,Object...objects)  
    {  
        BaseDao baseDao = null;  
        //========初始化JTable信息  
        columnNames = new Vector();  
        rowDates = new Vector();  
        columnNames.add("体检表号"); columnNames.add("学号");
        columnNames.add("姓名");  columnNames.add("身高（cm）");
        columnNames.add("体重（kg）");columnNames.add("胸围(cm)"); 
        columnNames.add("血压(mmHg)");  columnNames.add("沙眼");
        columnNames.add("胸透");columnNames.add("体检日期");
        columnNames.add("体检结果");columnNames.add("病史");
        try {  
            baseDao = new BaseDao();  
            
            List list= baseDao.query(sql, new ResultsetToHealthform(),objects);  
            if (list.size()>0) {
            	for (int i = 0; i < list.size(); i++) {
    				Healthform healthform=(Healthform) list.get(i);
    				//System.out.println(student.toString());
    				Vector row = new Vector(); 
                    row.add(healthform.getHno());                      
                    row.add(healthform.getSno()); 
                    row.add(healthform.getSname());
                    row.add(healthform.getHeight());                
                    row.add(healthform.getWeight());                
                    row.add(healthform.getChest());                  
                    row.add(healthform.getBpressure());           
                    row.add(healthform.getTracmStr()); 
                    row.add(healthform.getCx());                        
                    row.add(healthform.getPdate());                  
                    row.add(healthform.getPresult());              
                    row.add(healthform.getMedicalhistory());
                    rowDates.add(row); 
    			}                      
    		}	                       
        } catch (Exception e) {        
            // TODO: handle exception  
        	e.printStackTrace();
        }   
    }  
  
    public int getColumnCount() {  
  //告知列数，用标题数组的大小,这样表格就是rowData.size()行，columnNames.size()列了  
        return this.columnNames.size();  
    }  
  
    public int getRowCount() {   
        return this.rowDates.size(); 
        //这里是告知表格应该有多少行，我们返回rowDatas上的String数组个数
    }  
  
    @SuppressWarnings("rawtypes")
	public Object getValueAt(int row, int col) {  
        // TODO Auto-generated method stub  
        if(!rowDates.isEmpty())  
            return ((Vector)this.rowDates.get(row)).get(col);  
        else  
            return null;  
    }  
     
    public String getColumnName(int column) {  
        return (String)this.columnNames.get(column);  
      //这里是告知表格各列的列名，我们返回该列的列名
    }

}
